#include <bits/stdc++.h>

using namespace std;

using pii = pair<int, int>;

const int N = 1e5 + 10, L_MAX = 1e6 + 10;

struct Car {
    int d, v, a;
};

int n, m, L, V, p[N], s[N], e[N], mp[L_MAX], ok[N];
Car car[N];
vector<int> S[L_MAX], E[L_MAX];
vector<pii> abv;

int ceil_div(int a, int b) {
    int f = 1ll * a * b < 0 ? -1 : 1;
    a = abs(a), b = abs(b);
    return (a + b - 1) / b * f;
}

void check(int d, int v, int a, int i) {
    if(a > 0) {
        s[i] = min(max(d + (V * V - v * v) / (2 * a) + 1, 0), L + 1);
        e[i] = L + 1;
    } else if(a == 0) {
        s[i] = e[i] = L + 1;
        if(v > V) s[i] = d;
    } else {
        s[i] = d;
        e[i] = max(min(d + ceil_div(V * V - v * v, 2 * a), L + 1), d);
    }
    S[s[i]].push_back(i);
    E[e[i]].push_back(i);
}

void solve() {
    fill(ok, ok + N, 0);
    fill(S, S + L_MAX, vector<int>());
    fill(E, E + L_MAX, vector<int>());
    fill(mp, mp + L_MAX, 0);
    abv.clear();
    cin >> n >> m >> L >> V;
    for(int i = 0; i < n; i++) {
        int d, v, a;
        cin >> d >> v >> a;
        check(d, v, a, i);
    }
    int ans1 = 0;
    for(int i = 0; i < m; i++) {
        cin >> p[i];
        mp[p[i]]++;
    }
    set<int> det;
    for(int i = 0; i <= L; i++) {
        for(int j : S[i]) det.insert(j);
        for(int j : E[i]) if(det.find(j) != det.end()) det.erase(j);
        if(mp[i]) {
            ans1 += det.size();
            for(int j : det) abv.push_back({e[j] - 1, s[j]});
            det.clear();
        }
    }
    sort(abv.begin(), abv.end());
    int ans2 = m, j = 0;
    for(int i = 0; i < m && j < abv.size(); i++) {
        while(i < m - 1 && p[i + 1] <= abv[j].first) i++;
        ans2--;
        while(j < abv.size() && abv[j].second <= p[i]) j++;
    }
    cout << ans1 << " " << ans2 << "\n";
}


signed main() {
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);

    ios::sync_with_stdio(false);

    int T;
    cin >> T;
    while(T--) solve();
    return 0;
}